﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace GirisSayfasi
{

    public partial class FormGiris : Form
    {
        MySqlConnection baglan = Connection.baglan;
        public FormGiris()
        {
            

            InitializeComponent();

            
            MySqlDataAdapter adapter = new MySqlDataAdapter("select SirketAdi from sirketbilgileri", baglan);
            DataTable tablo = new DataTable();
            adapter.Fill(tablo);
            foreach (DataRow r in tablo.Rows)
            {
                cmbSirketSec.Items.Add(r["SirketAdi"].ToString());
            }
            MySqlDataAdapter kullaniciadapter = new MySqlDataAdapter("select KullaniciNick from kullanicilistesi", baglan);
            DataTable kullanicitablo = new DataTable();
            kullaniciadapter.Fill(kullanicitablo);
            foreach (DataRow r in kullanicitablo.Rows)
            {
                cmbKullaniciAdi.Items.Add(r["KullaniciNick"].ToString());
            }
        }
        AnaSayfa frm = new AnaSayfa();
        


        private void Form_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
           /* if (cmbSirketSec.Text=="") {
                MessageBox.Show("Şirket Seçimi Yapılmadı");
                cmbSirketSec.Focus();
            }
            else if (cmbKullaniciAdi.Text =="") {
                MessageBox.Show("Kullanıcı Adı Boş Bırakılamaz");
                cmbKullaniciAdi.Focus();
            }
            else if (txtSifre.Text == "")
            {
                MessageBox.Show("Şifre Boş Bırakılamaz");
                txtSifre.Focus();
            }
            
            else
            {*/
                baglan.Open();
                MySqlCommand cmd = new MySqlCommand("select * from kullanicilistesi where KullaniciNick = '" + cmbKullaniciAdi.Text + "' and KullaniciSifre ='" + txtSifre.Text + "' ", baglan);
                int Count = Convert.ToInt32(cmd.ExecuteScalar());

                if (Count == 0)

                /////if (Count != 0)
                {
                frm.Show();
                baglan.Close();
                this.Hide();
                }
                else
                {
                    MessageBox.Show("Hatalı Şifre");
                    txtSifre.Focus();
                    txtSifre.SelectAll();
                    baglan.Close();
                }
           ////// }
        }
        }
    }

